﻿// Please see documentation at https://docs.microsoft.com/aspnet/core/client-side/bundling-and-minification
// for details on configuring this project to bundle and minify static web assets.

// Write your JavaScript code.

function ShowToast(msg) {

    if (!$("#_Toast").length) {
        $("main").append(`
<div class="toast-container position-fixed top-0 start-0 p-3 m-5">
    <div class="toast" id="_Toast">  
      <div class="toast-header">
        <svg class="bd-placeholder-img rounded me-2" width="20" height="20" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" preserveAspectRatio="xMidYMid slice" focusable="false"><rect width="100%" height="100%" fill="#007aff"></rect></svg>
        <strong class="me-auto">忆客科技</strong>
      </div>
      <div class="toast-body" id="_ToastBody">
      </div>
    </div>
</div>
`);
    }
    $("#_ToastBody").html(msg);

    const toast = new bootstrap.Toast(document.getElementById('_Toast'));
    toast.show()

}

function ShowConfirm(msg, head) {
    if (head == null)
        head = "确认框";
    if (!$("#_Confirm").length) {
        $("main").append(`
<div class="modal" tabindex="-1" id="_Confirm">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title"></h5>
        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
      </div>
      <div class="modal-body">
        <p id="_ConfirmMsg"></p>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">取消</button>
        <button type="button" class="btn btn-primary">确定</button>
      </div>
    </div>
  </div>
</div>
`);
    }
    $("#_Confirm").find(".modal-title").html(head);
    $("#_ConfirmMsg").html(msg);
    //$("#_Confirm").fadeIn(200);
    $("#_Confirm").show();//.modal("show");


    return {
        on: function (cb) {
            $("#_Confirm").find('.btn-primary').off("click").on("click", function () {
                $("#_Confirm").hide(200);
                if (cb != null)
                    cb(true)
            });
            $("#_Confirm").find('.btn-secondary').off("click").on("click", function () {
                $("#_Confirm").hide(200);
                if (cb != null)
                    cb(false)
            });
        }
    };

}

